package com.starlink.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.hutool.core.convert.Convert;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.PageHelper;
import org.springframework.data.domain.Pageable;
import com.starlink.common.utils.AssertUtil;
import com.starlink.model.dtomapper.FreeDeliverySetDtoMapper;
import com.starlink.model.domain.FreeDeliverySetDO;
import com.starlink.mapper.FreeDeliverySetMapper;
import com.starlink.model.request.FreeDeliverySetRequest;
import com.starlink.service.FreeDeliverySetService;
import com.starlink.model.util.FreeDeliverySetConvert;
import com.starlink.model.vo.FreeDeliverySetVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static com.starlink.utils.PageUtils.getOrderBy;

import java.util.List;

/**
 * @author zhanghong
 */
@Service
public class FreeDeliverySetServiceImpl extends ServiceImpl<FreeDeliverySetMapper, FreeDeliverySetDO> implements FreeDeliverySetService {
    @Autowired
    private FreeDeliverySetMapper freeDeliverySetMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean add(FreeDeliverySetRequest request) {
        save(FreeDeliverySetDtoMapper.INSTANCE.request2DO(request));
        return true;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByKey(FreeDeliverySetRequest request) {
        AssertUtil.assertNotNull(request.getId(), "id不能为空");
        saveOrUpdate(FreeDeliverySetDtoMapper.INSTANCE.request2DO(request));
        return true;
    }

    @Override
    public FreeDeliverySetVO selectOne() {
        FreeDeliverySetDO deliverySetDO = this.lambdaQuery().one();
        FreeDeliverySetVO deliverySetVO = FreeDeliverySetDtoMapper.INSTANCE.do2VO(deliverySetDO);
        return deliverySetVO;
    }
}
